<?php

/**
 * Editionoptions form.
 *
 * @package    briefingPropel
 * @subpackage form
 * @author     Your name here
 */
class EditionoptionsForm extends BaseEditionoptionsForm
{
  
  public function configure()
  {
    
    parent::configure();
    
    $this->widgetSchema->setLabels(array(
        'idEditionOptions' => 'id edition options',  
        'moreText' => 'More text'
        ));
    
    //is_technical_terms
    $this->widgetSchema['is_technical_terms'] = new sfWidgetFormChoice(array(
        'label' => 'Technical terms',
        'choices' => array("No", "Yes"),
        'multiple' => false,
        'expanded' => true,
    ));
    
    $this->validatorSchema['is_technical_terms'] = new sfValidatorBoolean();
    //is_foraign_word
    $this->widgetSchema['is_foraign_word'] = new sfWidgetFormChoice(array(
        'label' => 'Foreign words',
        'choices' => array("No", "Yes"),
        'multiple' => false,
        'expanded' => true,
    ));
    $this->validatorSchema['is_foraign_word'] = new sfValidatorBoolean();
    //is_superlative
    $this->widgetSchema['is_superlative'] = new sfWidgetFormChoice(array(
        'label' => 'Superlative',
        'choices' => array("No", "Yes"),
        'multiple' => false,
        'expanded' => true,
    ));
    $this->validatorSchema['is_superlative'] = new sfValidatorBoolean();
    //is_old_language
    $this->widgetSchema['is_old_language'] = new sfWidgetFormChoice(array(
        'label' => 'Old language',
        'choices' => array("No", "Yes"),
        'multiple' => false,
        'expanded' => true,
    ));
    $this->validatorSchema['is_old_language'] = new sfValidatorBoolean();
    //is_start_of_sentence
    $this->widgetSchema['is_start_of_sentence'] = new sfWidgetFormChoice(array(
        'label' => 'Start of sentence',
        'choices' => array("No", "Yes"),
        'multiple' => false,
        'expanded' => true,
    ));
    $this->validatorSchema['is_start_of_sentence'] = new sfValidatorBoolean();
    //more text
    $this->widgetSchema['moreText'] = new sfWidgetFormTextarea(array(
        'label' => 'More text',
    ));
    $this->validatorSchema['moreText'] = new sfValidatorString(array(
        'required' => false
    ));
    
    //ownchoiceid
    $this->widgetSchema['ownChoiceId'] = new sfWidgetFormInputHidden();
    
    
    //Own choice
    $formOwnChoice;
    $ownChoice;

    //including the Other text medium form
    $savedOwnChoice = OwnchoicePeer::retrieveByPk($this->getObject()->getOwnchoiceid());

    if(is_null($savedOwnChoice))
    {
      $ownChoice = new Ownchoice();
      $formOwnChoice = new OwnchoiceForm($ownChoice);//OthertextmediumPeer::retrieveByPk($this->getObject()->getOthertextmediumid()));
    }
    else
    {
      $formOwnChoice = new OwnchoiceForm($savedOwnChoice);//OthertextmediumPeer::retrieveByPk($this->getObject()->getOthertextmediumid()));
    }
    
    $this->embedForm('Own choice', $formOwnChoice);//'otherTextMediumId', $formOtherMedia);
    
    
  }//configure
  
  
  
  protected function doSave($con = null)
  {
    
    if (null === $con)
    {
      $con = $this->getConnection();
    }

    $this->updateObject(
            $this->getValues()
            );
    //gets called first
    $this->saveEmbeddedForms($con);

    //save all the embedded objects
    $this->getObject()->setOwnchoice($this->getEmbeddedForm('Own choice')->getObject());
    
        
    //object is saved after embedded form
    $this->getObject()->save($con);

  }
}
